package com.firstgroup.dms.controller;

import com.firstgroup.dms.common.Result;
import com.firstgroup.dms.pojo.ProcurementInformation;
import com.firstgroup.dms.service.ProcurementService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("/api/procurement")
public class ProcurementController {
    @Resource
    private ProcurementService procurementService;

    @PostMapping("/add")
    public Result addProcurement(@RequestBody ProcurementInformation procurement) {
        return procurementService.addProcurement(procurement);
    }

    @GetMapping("/employees")
    public Result getEmployees() {
        return procurementService.getEmployees();
    }

    // 获取药品列表
    @GetMapping("/drugs")
    public Result getDrugs() {
        return procurementService.getDrugs();
    }

    // 获取药品详情
    @GetMapping("/drug/{id}")
    public Result getDrugById(@PathVariable Integer id) {
        return procurementService.getDrugById(id);
    }

    // 获取采购单列表
    @GetMapping("/list")
    public Result getProcurements(
            @RequestParam(required = false) String danjuhao,
            @RequestParam(required = false) String jingshouren,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int limit) {
        return procurementService.getProcurements(danjuhao, jingshouren, page, limit);
    }

    // 删除采购单
    @DeleteMapping("/delete/{id}")
    public Result deleteProcurement(@PathVariable Integer id) {
        return procurementService.deleteProcurement(id);
    }

    // 获取单个采购单信息
    @GetMapping("/{id}")
    public Result getProcurement(@PathVariable Integer id) {
        return procurementService.getProcurement(id);
    }
}